package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.common.exception.LyException;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import com.leyou.item.dto.SpecParamDTO;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecParamServiceImpl extends ServiceImpl<SpecParamMapper, SpecParam>implements SpecParamService {

    @Override
    public List<SpecParamDTO> queryParams(Long gid, Long cid,Boolean searching) {

        //健壮性判断
        if (gid==null && cid==null){
            throw new LyException(400,"查询条件不能为空");
        }
        //查询
        List<SpecParam>list= query()
                        .eq(null!=gid,"group_id",gid)
                        .eq(null!=cid,"category_id",cid)
                       .eq(null != searching, "searching", searching)
                        .list();
        return SpecParamDTO.convertEntityList(list);
    }


}
